package top.go2do.deviceSync.business.device.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import top.go2do.deviceSync.business.device.module.DevicePO;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author xingyuji
 * @CreateTime 2025/4/17 13:46
 */
public interface DeviceRepository extends JpaRepository<DevicePO, String>, JpaSpecificationExecutor<DevicePO> {
    @Modifying
    @Transactional
    @Query(value = "UPDATE devices SET last_online_time = :lastOnlineTime WHERE app_id = :appId AND device_id = :deviceId", nativeQuery = true)
    int updateHeartbeatIntervalById(@Param("lastOnlineTime") LocalDateTime lastOnlineTime, @Param("appId") String appId, @Param("deviceId") String deviceId);
}
